package com.yicong.ants.manager.business;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.util.Pair;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.blankj.utilcode.util.SizeUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition;
import com.cchao.simplelib.LibCore;
import com.cchao.simplelib.core.GlideApp;
import com.cchao.simplelib.core.ImageLoader;
import com.cchao.simplelib.core.Logs;
import com.cchao.simplelib.core.PrefHelper;
import com.cchao.simplelib.core.RxBus;
import com.cchao.simplelib.core.RxHelper;
import com.cchao.simplelib.core.UiHelper;
import com.cchao.simplelib.ui.activity.BaseActivity;
import com.cchao.simplelib.util.CallBacks;
import com.cchao.simplelib.util.StringHelper;
import com.cchao.simplelib.util.UrlUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.activity.BasicActivity;
import com.yicong.ants.bean.ExchangeNoticeBean;
import com.yicong.ants.bean.circle.AdItem;
import com.yicong.ants.bean.circle.PricingInfoItem;
import com.yicong.ants.bean.coin.LastTrans;
import com.yicong.ants.bean.coin.TransInfo;
import com.yicong.ants.bean.global.ClientConfig;
import com.yicong.ants.bean.me.sign.SignResult;
import com.yicong.ants.bean.scenic.ConsumeDetail;
import com.yicong.ants.bean.video.GiftInfoBean;
import com.yicong.ants.bean.video.GiftListBean;
import com.yicong.ants.databinding.DialogActivityBinding;
import com.yicong.ants.databinding.DialogAdPreviewBinding;
import com.yicong.ants.databinding.DialogAdReview0Binding;
import com.yicong.ants.databinding.DialogAdReview1Binding;
import com.yicong.ants.databinding.DialogAntLinkTipBinding;
import com.yicong.ants.databinding.DialogBottomItemBinding;
import com.yicong.ants.databinding.DialogCircleAdInfoBinding;
import com.yicong.ants.databinding.DialogCommonConfirmBinding;
import com.yicong.ants.databinding.DialogCommonSucBinding;
import com.yicong.ants.databinding.DialogCommonWarningBinding;
import com.yicong.ants.databinding.DialogConsumeDetailBinding;
import com.yicong.ants.databinding.DialogDisclaimerBinding;
import com.yicong.ants.databinding.DialogEnergyUpBinding;
import com.yicong.ants.databinding.DialogExchangNoticeBinding;
import com.yicong.ants.databinding.DialogGetTaskBinding;
import com.yicong.ants.databinding.DialogGiveGiftBinding;
import com.yicong.ants.databinding.DialogHtmlLinkBinding;
import com.yicong.ants.databinding.DialogNoticeBinding;
import com.yicong.ants.databinding.DialogPrivacyTipBinding;
import com.yicong.ants.databinding.DialogQrBinding;
import com.yicong.ants.databinding.DialogRedemptionConfirmationBinding;
import com.yicong.ants.databinding.DialogRewardAuthorBinding;
import com.yicong.ants.databinding.DialogRpBinding;
import com.yicong.ants.databinding.DialogShortVideoUploadBinding;
import com.yicong.ants.databinding.DialogSignScanResultBinding;
import com.yicong.ants.databinding.DialogStockTransBinding;
import com.yicong.ants.databinding.DialogTaskCompleteBinding;
import com.yicong.ants.databinding.DialogTaskCompleteNewBinding;
import com.yicong.ants.databinding.DialogTipBinding;
import com.yicong.ants.databinding.DialogTransQrBinding;
import com.yicong.ants.databinding.DialogWarehouseDetailsBinding;
import com.yicong.ants.manager.AppHelper;
import com.yicong.ants.manager.BusinessHelper;
import com.yicong.ants.manager.ImageHelper;
import com.yicong.ants.manager.RouterHelper;
import com.yicong.ants.manager.UserManager;
import com.yicong.ants.manager.config.ZzConfigs;
import com.yicong.ants.manager.holder.GlideRoundTransform;
import com.yicong.ants.manager.http.RetrofitHelper;
import com.yicong.ants.utils.AppUtils;
import com.yicong.ants.utils.CodeCreator;
import com.yicong.ants.utils.FileHelper;
import com.yicong.ants.utils.GlideUtils;
import com.yicong.ants.utils.MyRunnable;
import com.yicong.ants.utils.SPUtils;
import com.yicong.ants.utils.ToastUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.jiguang.api.utils.JCollectionAuth;

/**
 * @author cchao
 * @version 2019-11-11.
 */
public class Dialogs {

    /**
     * 日期选择，从当前时间开始
     */
    public static void showDataSelect(FragmentManager fragmentManager, CallBacks.Str callBack) {
        DatePickerDialog.OnDateSetListener listener = (view, year, monthOfYear, dayOfMonth) -> {
            String mon, day;
            ++monthOfYear;
            mon = monthOfYear < 10 ? "0" + monthOfYear : String.valueOf(monthOfYear);
            day = dayOfMonth < 10 ? "0" + dayOfMonth : String.valueOf(dayOfMonth);

            String time = year + "-" + mon + "-" + day;
            if (UserManager.notLogin()) {
                UiHelper.showToast("请先登录");
                return;
            }
            callBack.onCallBack(time);
        };

        Calendar now = Calendar.getInstance();
        DatePickerDialog dpd = DatePickerDialog.newInstance(
                listener,
                now.get(Calendar.YEAR),
                now.get(Calendar.MONTH),
                now.get(Calendar.DAY_OF_MONTH)
        );
        dpd.setThemeDark(false);
        dpd.vibrate(true);
        dpd.dismissOnPause(false);
        dpd.showYearPickerFirst(false);
        dpd.setVersion(DatePickerDialog.Version.VERSION_1);
        dpd.setAccentColor(UiHelper.getColor(R.color.appColor));
        dpd.setTitle("时间选择");
        dpd.show(fragmentManager, "Datepickerdialog");
    }

    /**
     * 显示 任务完成对话框
     */
    public static void showTaskSucNew(Context context, String mTitle, String ycTitle) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogTaskCompleteNewBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_task_complete_new, null, false);
        binding.setClick(v -> dialog.dismiss());

        if (mTitle != null && !mTitle.isEmpty() && new BigDecimal(mTitle).floatValue() != 0) {
            binding.mGroup.setVisibility(View.VISIBLE);
            binding.title.setText(mTitle);
        }
        if (ycTitle != null && !ycTitle.isEmpty() && new BigDecimal(ycTitle).floatValue() != 0) {
            binding.ycGroup.setVisibility(View.VISIBLE);
            binding.ycTitle.setText(ycTitle);
        }
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 显示 任务领取成功对话框
     */
    public static void showGetTaskSuc(Context context, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogGetTaskBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_get_task, null, false);
        binding.setStatus(0);
        binding.setClick(v -> dialog.dismiss());
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();
        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * yc兑换门票兑换须知
     */
    public static void showYcExchangeNotice(Context context, ExchangeNoticeBean bean, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        dialog.setCanceledOnTouchOutside(false);
        DialogExchangNoticeBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_exchang_notice, null, false);
        binding.layoutC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                binding.checkBox.setChecked(!binding.checkBox.isChecked());
            }
        });
        binding.setClick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (view.getId() == R.id.close) {
                    if (runnable!=null){
                        runnable.run();
                    }
                    dialog.dismiss();
                } else {
                    if (binding.checkBox.isChecked()) {
                        SPUtils.put(context, "YCExchangeNotice", true);
                        dialog.dismiss();
                    } else {
                        ToastUtils.showShort(context, "请阅读并同意兑换须知");
                    }
                }
            }
        });
        //配置文案
        binding.txLayout.removeAllViews();
        List<String> exchangeNotice = bean.getExchange_notice();
        for (int i = 0; i < exchangeNotice.size(); i++) {
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            View view = LayoutInflater.from(context).inflate(R.layout.item_exchange_yc_dialog, binding.txLayout, false);
            int padding = SizeUtils.dp2px(15);
            view.setPadding(padding, padding, padding, 0);
            TextView textView = view.findViewById(R.id.text);
            textView.setText(exchangeNotice.get(i));
            textView.setTextSize(16);
            textView.setTextColor(ContextCompat.getColor(context, R.color.new_text_color_1));
            binding.txLayout.addView(view, layoutParams);
        }
        //配置表格
        List<List<String>> exchangeInfo = bean.getExchange_info();
        binding.groupLayout.removeAllViews();
        for (int i = 0; i < exchangeInfo.size(); i++) {
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT);
            layoutParams.weight = 1;
            LinearLayout wl = new LinearLayout(context);
            wl.setOrientation(LinearLayout.VERTICAL);
            wl.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
            wl.setDividerDrawable(ContextCompat.getDrawable(context, R.drawable.divider_linear));
            List<String> notice = exchangeInfo.get(i);
            for (int j = 0; j < notice.size(); j++) {
                int height;
                int bgColor;
                int txColor;
                if (j == 0) {
                    txColor = ContextCompat.getColor(context, R.color.new_text_color_1);
                    bgColor = Color.parseColor("#F2F3F5");
                    height = SizeUtils.dp2px(60);
                } else {
                    txColor = ContextCompat.getColor(context, R.color.new_text_color_2);
                    bgColor = Color.parseColor("#FFFFFF");
                    height = SizeUtils.dp2px(45);
                }
                LinearLayout.LayoutParams txLayoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height);
                TextView textView = new TextView(context);
                textView.setTextSize(15);
                textView.setText(notice.get(j));
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundColor(bgColor);
                textView.setTextColor(txColor);
                wl.addView(textView, txLayoutParams);
            }

            binding.groupLayout.addView(wl, layoutParams);
        }

        dialog.show();
        requestDialogWidth90(dialog, binding.getRoot());
    }

    /**
     * 显示 任务领取失败对话框
     */
    public static void showGetTaskFail(Context context, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogGetTaskBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_get_task, null, false);
        binding.image.setImageResource(R.mipmap.img_common_popupnotification_shedtears);
        binding.setStatus(1);
        binding.setClick(v -> dialog.dismiss());
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();
        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 兑换确认输入密码对话框
     */
    public static void showRedemptionConfirmation(Context context, String number, MyRunnable<String> runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogRedemptionConfirmationBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_redemption_confirmation, null, false);
        String password = "";
        binding.setPassword(password);
        binding.setNumber(number);
        binding.setClick(v -> {
            if (v.getId() == R.id.topShopItemLl || v.getId() == R.id.close) {
                dialog.dismiss();
            } else if (v.getId() == R.id.sure) {
                dialog.dismiss();
                if (runnable == null) {
                    return;
                }
                runnable.run(binding.getPassword());
            }
        });
        dialog.show();
        requestDialogWidth90(dialog, binding.getRoot());
    }

    /**
     * 显示 任务完成对话框
     */
    public static void showTaskSuc(Context context, String title, String content, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogTaskCompleteBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_task_complete, null, false);
        binding.setClick(v -> dialog.dismiss());
        binding.content.setText(content);
        binding.title.setText(title);
        UiHelper.setVisibleElseGone(binding.content, StringHelper.isNotEmpty(content));
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 显示 任务完成对话框
     */
    public static void showCommonSuc(Context context, int resource, String title, String content, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogCommonSucBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_common_suc, null, false);
        binding.setClick(v -> dialog.dismiss());
        binding.image.setImageResource(resource);
        binding.content.setText(content);
        binding.title.setText(title);
        UiHelper.setVisibleElseGone(binding.content, StringHelper.isNotEmpty(content));
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 显示 任务完成对话框
     */
    public static void showHtmlLinkEdit(Context context, CallBacks.Str runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogHtmlLinkBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_html_link, null, false);
        binding.setClick(v -> {
            if (StringHelper.isNotEmpty(binding.editName.getText()) && StringHelper.isNotEmpty(binding.editLink.getText())) {
                runnable.onCallBack(binding.editName.getText().toString() + "##" + binding.editLink.getText().toString());
            }
            dialog.dismiss();
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }


    /**
     * 显示 任务完成对话框
     */
    public static void showCircleAd(Context context, AdItem adItem, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogCircleAdInfoBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_circle_ad_info, null, false);
        binding.setClick(v -> dialog.dismiss());
        binding.setBean(adItem);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    private static void requestDialogWidth80(Dialog dialog, View root) {
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(root);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = (int) (UiHelper.getScreenWidth() * 0.8);
        dialog.getWindow().setAttributes(p);

        root.requestLayout();
        dialog.show();
    }

    public static void requestDialogWidth90(Dialog dialog, View root) {
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(root);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = (int) (UiHelper.getScreenWidth() * 0.9);
        dialog.getWindow().setAttributes(p);

        root.requestLayout();
        dialog.show();
    }

    public static void requestDialogWidth100Height80(Dialog dialog, View root) {
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(root);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = UiHelper.getScreenWidth();
        p.height = (int) (UiHelper.getScreenHeight() * 0.8f);
        p.gravity = Gravity.BOTTOM;
        dialog.getWindow().setAttributes(p);

        root.requestLayout();
        dialog.show();
    }

    public static void requestDialogBottomWidth100(Dialog dialog, View root) {
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(root);
        dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = ViewGroup.LayoutParams.MATCH_PARENT;
        p.gravity = Gravity.BOTTOM;
        dialog.getWindow().setAttributes(p);

        root.requestLayout();
        dialog.show();
    }

    public static void requestDialogBottomWidth90(Dialog dialog, View root) {
        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(root);
        dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = (int) (UiHelper.getScreenWidth() * 0.9f);
        p.gravity = Gravity.BOTTOM;
        dialog.getWindow().setAttributes(p);

        root.requestLayout();
        dialog.show();
    }

    private static void requestDialogHeightLimit(Dialog dialog, View root, float height) {
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(root);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = (int) (UiHelper.getScreenWidth() * height);
        dialog.getWindow().setAttributes(p);

        root.requestLayout();
        dialog.show();
    }

    /**
     * 显示 获得活跃度
     */
    public static void showEnergySuc(Context context, String title, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogEnergyUpBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_energy_up, null, false);
        binding.setClick(v -> dialog.dismiss());
        binding.title.setText(title);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 显示 获得活跃度
     */
    public static void showAdReview(Context context, int style, String text, String image, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        View view;
        if (style == 0) {
            DialogAdReview0Binding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_ad_review_0, null, false);
            binding.setClick(v -> dialog.dismiss());
            binding.title.setText(text);
            ImageHelper.setLayoutParamsWh(binding.image, (int) (UiHelper.getScreenWidth() * 0.8f - UiHelper.dp2px(32)), 16, 9);
            ImageHelper.loadImageRound(binding.image, image, 2);
            view = binding.getRoot();
        } else {
            DialogAdReview1Binding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_ad_review_1, null, false);
            binding.setClick(v -> dialog.dismiss());
            binding.title.setText(text);
            ImageHelper.setLayoutParamsWh(binding.image, (int) (UiHelper.getScreenWidth() / 2.7f), 16, 9);
            ImageHelper.loadImageRound(binding.image, image, 2);
            view = binding.getRoot();
        }

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setOnDismissListener(dialog1 -> {
            if (runnable == null) {
                return;
            }
            runnable.run();
        });
        dialog.show();

        requestDialogWidth80(dialog, view);
    }

    public static void noticeAction(Activity context, ClientConfig.NoticeItem noticeItem) {
        if (noticeItem == null) {
            return;
        }
        // 操作:0=无,1=跳转link,2=文字弹窗',
        switch (noticeItem.getOperation()) {
            case 0:
                return;
            case 1:
                RouterHelper.router(context, noticeItem.getLink());
                break;
            case 2:
                showContentNotice(context, noticeItem);
                break;
        }
    }

    /**
     * 显示 notice
     *
     * @return 是否显示
     */
    public static boolean showNotice(Activity context, ClientConfig.NoticeItem noticeItem) {
        if (noticeItem == null) {
            return false;
        }
        if (PrefHelper.getInt(Constants.Prefs.Last_Notice_Showed_Id, 1) >= noticeItem.getId()) {
            return false;
        }
        if (StringHelper.isEmpty(noticeItem.getContent())) {
            return false;
        }

        showContentNotice(context, noticeItem);
        PrefHelper.putInt(Constants.Prefs.Last_Notice_Showed_Id, noticeItem.getId());
        return true;
    }

    private static void showContentNotice(Activity context, ClientConfig.NoticeItem noticeItem) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogNoticeBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_notice, null, false);
        binding.setClick(v -> {
            RouterHelper.router(context, noticeItem.getLink());
            dialog.dismiss();
        });
        binding.content.setText(Html.fromHtml(noticeItem.getContent()));
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    public static void showCommonWarning(Activity context, String content, Runnable confirmCall) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogCommonWarningBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_common_warning, null, false);
        binding.setClick(v -> {
            dialog.dismiss();
            switch (v.getId()) {
                case R.id.confirm:
                    if (confirmCall != null) {
                        confirmCall.run();
                    }
                    break;
                case R.id.cancel:
                    break;
            }
        });
        binding.content.setText(content);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    public static void showCommonTipImage(Activity context, String image, Runnable confirmCall) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogCommonConfirmBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_common_confirm, null, false);
        binding.setClick(v -> {
            dialog.dismiss();
            switch (v.getId()) {
                case R.id.confirm:
                    if (confirmCall != null) {
                        confirmCall.run();
                    }
                    break;
                case R.id.cancel:
                    break;
            }
        });
//        binding.content.setText(Html.fromHtml(content));
        ImageLoader.loadImage(binding.content, image);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 显示 活动提示
     *
     * @return 是否显示
     */
    public static boolean showActivity(Activity context, ClientConfig.NoticeItem activity) {
        if (activity == null) {
            return false;
        }

        if (PrefHelper.getInt(Constants.Prefs.Last_Activity_Showed_Id, 1) >= activity.getId() && activity.isShowOnce()) {
            return false;
        }

        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogActivityBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_activity, null, false);
        binding.setBean(activity);
        binding.setClick(v -> {
            dialog.dismiss();
            switch (v.getId()) {
                case R.id.image:
                    RouterHelper.router(context, activity.getLink());
                    break;
                case R.id.close:
                    break;
            }
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth90(dialog, binding.getRoot());
        if (activity.isShowOnce()) {
            PrefHelper.putInt(Constants.Prefs.Last_Activity_Showed_Id, activity.getId());
        }
        return true;
    }

    /**
     * 转赠码
     */
    public static void showTransQr(Activity activity, String content) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogTransQrBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_trans_qr, null, false);
//        Bitmap logo = BitmapFactory.decodeResource(activity.getResources(), R.mipmap-xxhdpi.ic_launcher2);
//        Bitmap bitmap = CodeCreator.createQRCode(content, 600, 600, logo);
        Glide.with(activity).asBitmap()
                .load(UserManager.getUserBean().getAvatar()).override(200, 200)
                .transform(new GlideRoundTransform(13, ContextCompat.getColor(activity, R.color.white), 2))
                .centerCrop()
                .into(new CustomTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                        GlideRoundTransform transform = new GlideRoundTransform(13, ContextCompat.getColor(activity, R.color.white), 2);
                        Bitmap bitmap = CodeCreator.createQRCode(content, 600, 600, transform.roundCrop(resource));
                        binding.qrCode.setImageBitmap(bitmap);
                    }

                    @Override
                    public void onLoadCleared(@Nullable Drawable placeholder) {

                    }
                });

//        binding.qrCode.setImageBitmap(bitmap);
        binding.setClick(v -> {
            switch (v.getId()) {
                case R.id.close:
                    dialog.dismiss();
                    break;

                case R.id.confirm:
                    RxHelper.timerConsumer(200, aLong ->
                            FileHelper.saveViewToDirPic((BaseActivity) activity, binding.groupView));
                    break;
            }
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth90(dialog, binding.getRoot());
    }

    /**
     * 抖音码
     */
    public static void showQrContent(Activity activity, String desc, String content) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogQrBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_qr, null, false);
        Bitmap logo = BitmapFactory.decodeResource(activity.getResources(), R.mipmap.ic_launcher2);
        Bitmap bitmap = CodeCreator.createQRCode(content, 600, 600, logo);
        binding.qrCode.setImageBitmap(bitmap);
        binding.desc.setText(desc);
        binding.setClick(v -> {
            switch (v.getId()) {
                case R.id.close:
                    dialog.dismiss();
                    break;

                case R.id.confirm:
                    RxHelper.timerConsumer(200, aLong -> {
                        //
                        ImageHelper.viewSave2Image(binding.getRoot(), binding.getRoot().getContext());
                    });
/*                    File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
                    FileUtils.createOrExistsDir(dir);
                    File imageFile = new File(dir, "jpg_" + System.currentTimeMillis() + ".jpg");
                    BitmapUtils.compressBmpToFile(bitmap, imageFile);
                    UiHelper.showToast("图片已保存 " + imageFile.getAbsolutePath());*/
                    break;
            }
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 抖音码
     */
    public static Dialog showPrivacyAllow(Activity activity, Runnable runnable) {
        return showPrivacyAllow(activity, false, runnable);
    }

    public static Dialog showPrivacyAllow(Activity activity, boolean isStart, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogPrivacyTipBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_privacy_tip, null, false);

        binding.title.setText("蚁丛旅游用户使用协议及隐私政策");
        String str = AppUtils.getAssetsString(activity);
        int ys = str.indexOf("《隐私权政策》");
        int yh = str.indexOf("《用户协议》");
        int sf = str.indexOf("《个人信息第三方共享清单》");

        SpannableStringBuilder builder = new SpannableStringBuilder(str);

        //-----------------------------------------------------------------------------1
        ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ContextCompat.getColor(activity, R.color.bluePrimaryDark));
        builder.setSpan(foregroundColorSpan, ys, ys + 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new StyleSpan(Typeface.BOLD), ys, ys + 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                ZzConfigs.toWebActivity(activity, "隐私协议", "http://yc_private.yctourism.com/privacy.html");
            }

            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                ds.setUnderlineText(false);
            }
        };
        builder.setSpan(clickableSpan, ys, ys + 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        //-----------------------------------------------------------------------------3

        ForegroundColorSpan foregroundColorSpan2 = new ForegroundColorSpan(ContextCompat.getColor(activity, R.color.bluePrimaryDark));
        builder.setSpan(foregroundColorSpan2, yh, yh + 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new StyleSpan(Typeface.BOLD), yh, yh + 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ClickableSpan clickableSpan2 = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                ZzConfigs.toWebActivity(activity, "用户协议", "http://api.yctourism.com/api/v2/web/agreement");
            }

            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                ds.setUnderlineText(false);
            }
        };
        builder.setSpan(clickableSpan2, yh, yh + 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        //-----------------------------------------------------------------------------2
        ForegroundColorSpan foregroundColorSpan3 = new ForegroundColorSpan(ContextCompat.getColor(activity, R.color.bluePrimaryDark));
        builder.setSpan(foregroundColorSpan3, sf, sf + 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new StyleSpan(Typeface.BOLD), sf, sf + 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ClickableSpan clickableSpan3 = new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                ZzConfigs.toWebActivity(activity, "个人信息第三方共享清单", "http://yc_private.yctourism.com/infoShareList.html");
            }

            @Override
            public void updateDrawState(@NonNull TextPaint ds) {
                ds.setUnderlineText(false);
            }
        };
        builder.setSpan(clickableSpan3, sf, sf + 13, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        binding.content.setMovementMethod(LinkMovementMethod.getInstance());
        binding.content.setText(builder);

        binding.setClick(v -> {
            switch (v.getId()) {
                case R.id.close:
                    dialog.dismiss();
                    if (!isStart) {
                        JCollectionAuth.setAuth(activity, false);
                        showPrivacyTips(activity, runnable);
                    }
                    break;
                case R.id.confirm:
                    dialog.dismiss();
                    runnable.run();
                    break;
            }
        });
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
        return dialog;
    }

    private static void showPrivacyTips(Activity activity, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogTipBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_tip, null, false);
        binding.content.setText("若不同意，很遗憾我们将无法为您提供完整服务。");
        binding.setClick(v -> {
            int id = v.getId();
            if (id == R.id.close) {
                dialog.dismiss();
                activity.finish();
                activity.startActivity(new Intent(activity, BasicActivity.class));
            } else if (id == R.id.confirm) {
                dialog.dismiss();
                showPrivacyAllow(activity, runnable);
            }
        });
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 显示 门票和仓库互转
     */
    public static void showStockTran(Context context, TransInfo transInfo, int type, StockCallBack runnable) {
        showStockTran(context, transInfo, type, 0, runnable);
    }

    public static void showYcStockTran(Context context, TransInfo transInfo, int type, StockCallBack runnable) {
        showStockTran(context, transInfo, type, 1, runnable);
    }

    public static void showStockTran(Context context, TransInfo transInfo, int type, int status, StockCallBack runnable) {
        String title = type == 10 ? "转入仓库" : "转出仓库";
        String unit = status == 1 ? "yc" : "门票";
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogStockTransBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_stock_trans, null, false);
        binding.setStatus(status);
        binding.apply.setEnabled(false);
        binding.apply.setAlpha(0.5f);
        binding.title.setText(title);
        binding.coin.setText(transInfo.getCoin());
        binding.canTran.setText(String.valueOf(transInfo.getCan_trans_coin()));
        binding.close.setOnClickListener(view -> dialog.dismiss());
        UiHelper.setVisibleElseGone(binding.transInTip, type == 10);
        binding.stock.setText(String.valueOf(transInfo.getStock()));
        binding.editAmount.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

                if (transInfo.getTax_level() < 0 && type == 10) {
                    UiHelper.showToast("您的账号无权转赠");
                    return;
                }
                if (StringHelper.isEmpty(s)) {
                    binding.tax.setText("0" + unit);
                    binding.tax.setTextColor(UiHelper.getColor(R.color.themeTextDark));
                    return;
                }
                try {
                    if (Float.parseFloat(s.toString()) < 1) {
                        binding.tax.setText("最少需转换1" + unit);
                        binding.tax.setTextColor(UiHelper.getColor(R.color.red_primary));
                        return;
                    }
                    float canTransCoin = type == 10 ? Float.parseFloat(transInfo.getCan_trans_coin()) : Float.parseFloat(transInfo.getStock());
                    if (Float.parseFloat(s.toString()) > canTransCoin) {
                        UiHelper.showToast(type == 10 ? "超出最大可转入" + unit + "数" : "超出最大可转出" + unit + "数");
                        binding.tax.setText(unit + "不足");
                        binding.tax.setTextColor(UiHelper.getColor(R.color.red_primary));
                        return;
                    }

                    binding.tax.setText("0" + unit);
                    binding.total.setText("0" + unit);
                    if (type == 10) {
                        binding.tax.setText(BusinessHelper.calTax(Float.parseFloat(s.toString()), transInfo.getTax_level()).first + unit);
                        binding.total.setText(BusinessHelper.calTax(Float.parseFloat(s.toString()), transInfo.getTax_level()).second + unit);
                    } else {
                        binding.total.setText(s.toString() + unit);
                    }
                    binding.tax.setTextColor(UiHelper.getColor(R.color.red_primary));
                    binding.total.setTextColor(UiHelper.getColor(R.color.themeTextDark));
                } catch (Exception ex) {

                }

                if (binding.editAmount.getText().toString().length() <= 0 || binding.payPwdEdit.getText().toString().length() < 4) {
                    binding.apply.setEnabled(false);
                    binding.apply.setAlpha(0.5f);
                } else {
                    binding.apply.setEnabled(true);
                    binding.apply.setAlpha(1);
                }
            }
        });
        binding.payPwdEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (binding.editAmount.getText().toString().length() <= 0 || binding.payPwdEdit.getText().toString().length() < 4) {
                    binding.apply.setEnabled(false);
                    binding.apply.setAlpha(0.5f);
                } else {
                    binding.apply.setEnabled(true);
                    binding.apply.setAlpha(1);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        binding.apply.setOnClickListener(v -> {
            try {
                if (Float.parseFloat(binding.editAmount.getText().toString()) < 0) {
                    UiHelper.showToast("请输入转换数量");
                    return;
                }
                if (StringHelper.isEmpty(binding.payPwdEdit)) {
                    UiHelper.showToast("请输入支付密码");
                    return;
                }
            } catch (Exception exception) {
                UiHelper.showToast("请正确输入内容");
                return;
            }

            dialog.dismiss();
            if (runnable != null) {
                runnable.call(binding.editAmount.getText().toString(), binding.payPwdEdit.getText().toString());
            }
        });
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        requestDialogWidth90(dialog, binding.getRoot());
    }

    /**
     * 显示 门票和仓库互转
     */
    public static void showConsumeDetail(Context context, Pair<String, String> triple, ConsumeDetail consumeDetail, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogConsumeDetailBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_consume_detail, null, false);
        binding.title.setText("确定预订后，订单信息将无法修改，消耗的门票活跃度等概不退换。\n仅限本人预约使用，严禁为他人预订，一经发现永久封号！");
        binding.scenicName.setText(triple.first);
        binding.time.setText(triple.second);
        binding.name.setText(UserManager.getUserBean().getId_card_name());

        binding.preCoin.setText("-" + consumeDetail.getPre_coin());
//        binding.tax.setText("-" + consumeDetail.getTax());
        binding.energy.setText("-" + consumeDetail.getDeduct_energy());
        binding.close.setOnClickListener(v -> {
            dialog.dismiss();
        });
        binding.apply.setOnClickListener(v -> {
            dialog.dismiss();
            if (runnable != null) {
                runnable.run();
            }
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }


    /**
     * 打赏作者
     */
    public static void rewardAuthor(Context context, TransInfo mTransInfo, StockCallBack runnable) {
        if (UserManager.notLogin()) {
            UiHelper.showToast("您还没有登录");
            return;
        }
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogRewardAuthorBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_reward_author, null, false);
        binding.coin.setText(UserManager.getUserBean().getCoin());
        binding.editAmount.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                try {
                    if (mTransInfo.getTax_level() < 0) {
                        UiHelper.showToast("您的账号无权转赠");
                        return;
                    }

                    if (Float.parseFloat(s.toString()) > Float.parseFloat(mTransInfo.getCan_trans_coin())) {
                        UiHelper.showToast("您的门票余额不足");
                        return;
                    }

                    if (Float.parseFloat(s.toString()) > Float.parseFloat(mTransInfo.getCan_trans_coin())) {
                        UiHelper.showToast("超出最大可转赠门票");
                        return;
                    }
                    binding.taxNum.setText(Float.parseFloat(s.toString()) * mTransInfo.getTax_level() + "门票");
                } catch (Exception ex) {

                }
            }
        });
        binding.apply.setOnClickListener(v -> {
            try {
                if (Float.parseFloat(binding.editAmount.getText().toString()) < 0.1) {
                    UiHelper.showToast("最小可转赠门票数 0.1");
                    return;
                }
                if (Float.parseFloat(binding.editAmount.getText().toString()) < 0) {
                    UiHelper.showToast("请输入转换数量");
                    return;
                }
                if (StringHelper.isEmpty(binding.payPwdEdit)) {
                    UiHelper.showToast("请输入支付密码");
                    return;
                }
            } catch (Exception exception) {
                UiHelper.showToast("请正确输入内容");
                return;
            }

            dialog.dismiss();
            if (runnable != null) {
                runnable.call(binding.editAmount.getText().toString(), binding.payPwdEdit.getText().toString());
            }
        });
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 送礼物
     */
    public static void giveGift(Context context, GiftInfoBean giftInfo, GiftListBean giftListBean, StockCallBack runnable) {
        if (UserManager.notLogin()) {
            UiHelper.showToast("您还没有登录");
            return;
        }
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogGiveGiftBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_give_gift, null, false);
        final int[] giftNumber = {Integer.parseInt(binding.tvGiftNumber.getText().toString())};
        GlideApp.with(context).load(giftListBean.getGift_img()).into(binding.ivGift);
        binding.tvBalance.setText(UserManager.getUserBean().getCoin());
        binding.tvNeedCoupon.setText(String.valueOf(giftInfo.getGift_coin()));
        binding.tvPrice.setText(String.format("%s 门票 / 个", giftInfo.getGift_coin()));
        binding.tvProcedureCost.setText(String.valueOf((giftNumber[0] * giftInfo.getTax_level()) * giftInfo.getGift_coin()));

        binding.tvAdd.setOnClickListener(view -> {
            if (giftNumber[0] * giftInfo.getGift_coin() > Float.parseFloat(UserManager.getUserBean().getCoin())) {
                ToastUtils.show(context, "余额不足", 3);
                return;
            }
            giftNumber[0]++;
            binding.tvGiftNumber.setText(String.valueOf(giftNumber[0]));
            binding.tvNeedCoupon.setText(String.valueOf(giftNumber[0] * giftInfo.getGift_coin()));
            binding.tvProcedureCost.setText(String.valueOf((giftNumber[0] * giftInfo.getTax_level()) * giftInfo.getGift_coin()));
        });


        binding.tvReduce.setOnClickListener(view -> {
            if (giftNumber[0] == 1) {
                UiHelper.showToast("礼物数量不能是0");
                return;
            }
            giftNumber[0]--;
            binding.tvGiftNumber.setText(String.valueOf(giftNumber[0]));
            binding.tvNeedCoupon.setText(String.valueOf(giftNumber[0] * giftInfo.getGift_coin()));
            binding.tvProcedureCost.setText(String.valueOf(giftNumber[0] * giftInfo.getTax_level() * giftInfo.getGift_coin()));
        });

        binding.stvGive.setOnClickListener(view -> {
            if (StringHelper.isEmpty(binding.edtPassword.getText().toString())) {
                UiHelper.showToast("请输入支付密码");
                return;
            }
            if (binding.edtPassword.getText().toString().length() != 6) {
                UiHelper.showToast("支付密码必须是6位数字");
                return;
            }
            if (runnable != null) {
                runnable.call(binding.tvGiftNumber.getText().toString(), binding.edtPassword.getText().toString());
            }
            dialog.dismiss();
        });

        binding.close.setOnClickListener(view -> {
            dialog.dismiss();
        });

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    public static void showTaskDisclaimer(BaseActivity activity, Runnable runnable) {
        // 最后提示的时间
        long lastTime = PrefHelper.getLong(Constants.Prefs.Last_Task_Disclaimer_Time, 0L);
        int tipTimes = PrefHelper.getInt(Constants.Prefs.Task_Disclaimer_Times, 0);
        // 当前时间大于  最后提示的时间 + (times*2*86400*1000;
        if (System.currentTimeMillis() < lastTime + tipTimes * 2 * 86400 * 1000) {
            runnable.run();
            return;
        }

        String content = AppHelper.getUmConfig("ad_disclaimer"
                , "1, 广告内容由广告商提供。相关产品，服务将由第三方承担。\n2. 蚁丛旅游用户在购买或使用广告推荐的产品，服务等造成的损失。蚁丛旅游对其概不负责，亦不承担任何法律责任。\n3. 您的使用行为将被视为对本声明全部内容的认可。");

        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogDisclaimerBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_disclaimer, null, false);
        binding.title.setText("免责声明");
        binding.content.setText(content);
        binding.setClick(v -> {
            PrefHelper.putInt(Constants.Prefs.Task_Disclaimer_Times, tipTimes + 1);
            PrefHelper.putLong(Constants.Prefs.Last_Task_Disclaimer_Time, System.currentTimeMillis());
            dialog.dismiss();
            runnable.run();
        });

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    public static void showDisclaimer(Activity activity, String title, String content, String pref, Runnable runnable) {
        if (PrefHelper.getBoolean(pref, false)) {
            runnable.run();
            return;
        }
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogDisclaimerBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.dialog_disclaimer, null, false);
        binding.title.setText(title);
        binding.content.setText(content);
        binding.setClick(v -> {
            PrefHelper.putBoolean(pref, true);
            dialog.dismiss();
            runnable.run();
        });

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    /**
     * 发现蚁丛链接，是否打开
     */
    public static void showAntLinkRouter(Activity activity, String link, Runnable runnable) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogAntLinkTipBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity)
                , R.layout.dialog_ant_link_tip, null, false);
        binding.content.setText(link);
        binding.setClick(v -> {
            switch (v.getId()) {
                case R.id.close:
                    dialog.dismiss();
                    break;
                case R.id.confirm:
                    dialog.dismiss();
                    runnable.run();
                    break;
            }
        });

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    public static Dialog realCheckDialog;

    public static void showRealCheck2(Activity activity, String url) {
        String load = UrlUtil.appendParameter(url, LibCore.getInfo().getWebParams());
        Logs.d("showRealCheck2 " + load);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        View view = activity.getLayoutInflater().inflate(R.layout.dialog_real_check, null);
        WebView webView = (WebView) view.findViewById(R.id.web_view_field);

        WebSettings settings = webView.getSettings();
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        // ZoomControls（就是放大放小按钮） 是个渐变的过程（渐变未完成就destroy）会导致View not attached to window manager
        settings.setDisplayZoomControls(false);
        settings.setDatabaseEnabled(true);
        settings.setGeolocationDatabasePath(activity.getDir("database", Context.MODE_PRIVATE).getPath());
        // 启用地理定位
        settings.setGeolocationEnabled(true);
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
        settings.setAllowFileAccess(true);
        settings.setAppCacheEnabled(false);
        // 设置支持DomStorage
        settings.setDomStorageEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);

        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String s) {
                Logs.d("shouldOverrideUrlLoading2 " + s);
                if (realCheckDialog == null) {
                    return super.shouldOverrideUrlLoading(webView, s);
                }
                if (s.contains("/api/v2/web/apps")) {
                    Logs.d("shouldOverrideUrlLoading3 " + UrlUtil.getValueFromUrl(s, "type"));
                    switch (UrlUtil.getValueFromUrl(s, "type")) {
                        case "close":
                            realCheckDialog.dismiss();
                            return true;
                        case "success":
                            RxBus.get().postEvent(Constants.Event.Real_Check_Suc);
                            realCheckDialog.dismiss();
                            return true;
                    }
                }
                return super.shouldOverrideUrlLoading(webView, s);
            }
        });

        webView.loadUrl(load);
        builder.setView(view);
//        builder.setPositiveButton(R.string.confirm, null);
        realCheckDialog = builder.create();
        realCheckDialog.show();

        realCheckDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        realCheckDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        WindowManager.LayoutParams p = realCheckDialog.getWindow().getAttributes();
        p.width = (int) (UiHelper.getScreenWidth() * 0.8);
        webView.getLayoutParams().height = (int) (UiHelper.getScreenWidth() * 0.8);
        realCheckDialog.getWindow().setAttributes(p);

        webView.requestLayout();
        realCheckDialog.show();
    }

    /**
     * 短视频压缩进度
     */
    public static CallBacks.Int showShortVideoUpload(Activity activity) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogShortVideoUploadBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity)
                , R.layout.dialog_short_video_upload, null, false);
        CallBacks.Int run = new CallBacks.Int() {
            @Override
            public void onCallBack(int progress) {
                binding.content.setText("正在优化视频内容: " + progress + " %");
                binding.progress.setProgress(progress);
                if (progress >= 100) {
                    dialog.dismiss();
                }
            }
        };

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
        return run;
    }

    /**
     * 短视频压缩进度
     */
    public static void showAdPreview(Activity activity, PricingInfoItem item) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogAdPreviewBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity)
                , R.layout.dialog_ad_preview, null, false);

        binding.setBean(item);
        binding.setClick(v -> {
            dialog.dismiss();
        });

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth80(dialog, binding.getRoot());
    }

    public static void showSignSingle(BaseActivity activity, SignResult result) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogSignScanResultBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity)
                , R.layout.dialog_sign_scan_result, null, false);
        binding.setBean(result);
        binding.setClick(v -> {
            switch (v.getId()) {
                case R.id.main_self_sign:
                    signItem(activity, dialog, 1, binding);
                    break;
                case R.id.main_other_sign:
                case R.id.main_other_sign2:
                    signItem(activity, dialog, 0, binding);
                    break;
                case R.id.close:
                    dialog.dismiss();
                    break;
            }
        });

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        requestDialogWidth90(dialog, binding.getRoot());
    }

    public static void signItem(BaseActivity activity, Dialog dialog, int is_self, DialogSignScanResultBinding binding) {
        Map<String, String> map = new HashMap<>();
        map.put("activity_id", BusinessHelper.mActivityId);
        map.put("content", BusinessHelper.mSignScanContent);
        map.put("is_self", String.valueOf(is_self));
        activity.showProgress();
        activity.addSubscribe(RetrofitHelper.getLineApi().startSign(map)
                .compose(RxHelper.toMain())
                .subscribe(respBean -> {
                    activity.hideProgress();
                    if (respBean.isCodeFail()) {
                        activity.showToast(respBean.getMsg());
                        return;
                    }
                    binding.setBean(respBean.getData());
                    dialog.dismiss();
                    RxBus.get().postEvent(Constants.Event.Sign_List_Update);
                }, RxHelper.getHideProgressConsumer(activity)));
    }

    public static void showClearCache(Activity activity, CallBacks.Int callback) {
        new AlertDialog.Builder(activity)
                .setMessage("确定要清除缓存？")
                .setPositiveButton("确定", (dialogInterface, i) -> GlideUtils.clearCache(activity, callback))
                .setNegativeButton("取消", null)
                .show();
    }

    /**
     * 显示 实人认证对话框
     */
    public static void showRpDialog(Context context, String content, @NonNull DialogInterface.OnClickListener listener) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        dialog.setCancelable(false);
        DialogRpBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.dialog_rp, null, false);
        binding.contentTv.setText(content);
        binding.setClick(v -> {
            switch (v.getId()) {
                case R.id.confirmBtn:
                    listener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    break;
                case R.id.cancelBtn:
                    listener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                    break;
            }
            dialog.dismiss();
        });
        dialog.show();
        requestDialogWidth80(dialog, binding.getRoot());
    }

    public interface StockCallBack {
        void call(String amount, String payPwd);
    }

    /**
     * 仓库明细
     */
    public static void showWarehouseDetails(BaseActivity activity, List<LastTrans> list, DialogInterface.OnClickListener listener) {
        Dialog dialog = new AlertDialog.Builder(activity).create();
        DialogWarehouseDetailsBinding binding = DataBindingUtil.inflate(LayoutInflater.from(activity)
                , R.layout.dialog_warehouse_details, null, false);
        binding.setClick(v -> {
            if (v.getId() == R.id.close) {
                dialog.dismiss();
            }
        });
        BaseQuickAdapter<LastTrans, BaseViewHolder> adapter = new BaseQuickAdapter<LastTrans, BaseViewHolder>(R.layout.item_warehouse_details, list) {
            @Override
            protected void convert(BaseViewHolder helper, LastTrans item) {
                helper.setText(R.id.number, item.getId());
                helper.setText(R.id.name, item.getId_card_name());
                helper.setText(R.id.phone, item.getMobile());
            }
        };
        adapter.setOnItemClickListener((adapter1, view, position) -> {
            if (listener != null) {
                listener.onClick(null, position);
            }
            dialog.dismiss();
        });
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recycler.setLayoutManager(manager);
        binding.recycler.setAdapter(adapter);
        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        dialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                View.SYSTEM_UI_FLAG_FULLSCREEN |
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        dialog.getWindow().setNavigationBarColor(ContextCompat.getColor(activity, R.color.white));

        requestDialogBottomWidth100(dialog, binding.getRoot());
    }


    /**
     * 底部菜单弹窗
     */
    public static void showBottomItemDialog(Context context, String title, String[] items, DialogInterface.OnClickListener listener) {
        Dialog dialog = new AlertDialog.Builder(context).create();
        DialogBottomItemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context)
                , R.layout.dialog_bottom_item, null, false);
        binding.title.setText(title);
        binding.setClick(v -> {
            if (v.getId() == R.id.close) {
                dialog.dismiss();
            }
        });
        List<String> list = new ArrayList<>();
        Collections.addAll(list, items);
        BaseQuickAdapter<String, BaseViewHolder> adapter = new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_dialog_bottom_text, list) {
            @Override
            protected void convert(BaseViewHolder helper, String item) {
                helper.setText(R.id.text, item);
            }
        };
        adapter.setOnItemClickListener((adapter1, view, position) -> {
            dialog.dismiss();
            if (listener != null) {
                listener.onClick(null, position);
            }
        });
        LinearLayoutManager manager = new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        binding.recycler.setLayoutManager(manager);
        binding.recycler.setAdapter(adapter);

        dialog.setCancelable(true);
        dialog.setCanceledOnTouchOutside(true);
        dialog.show();

        dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setContentView(binding.getRoot());
        dialog.getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams p = dialog.getWindow().getAttributes();
        p.width = (int) (UiHelper.getScreenWidth() * 1f);
        p.height = (int) (UiHelper.getScreenHeight() * 0.5f);
        p.gravity = Gravity.BOTTOM;
        dialog.getWindow().setAttributes(p);

        binding.getRoot().requestLayout();
        dialog.show();
    }
}
